package com.me.services.db;

import com.me.dao.IUserDao;
import com.me.dao.normal.NormalUserDao;
import com.me.model.User;
import com.me.model.normal.NormalUser;
import com.me.services.IUserService;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class UserDbService implements IUserService<NormalUser> {
	IUserDao<NormalUser> uDao;
	
	public UserDbService() {
		this.uDao = new NormalUserDao();
	}
	
	@Override
	public boolean isUserExist(String userName) {
		return uDao.isUserExist(userName);
	}
	
	@Override
	public NormalUser login(String uname, String pwd) {
		return (NormalUser)uDao.login(uname, pwd);
	}
	
	@Override
	public boolean isUserCanLogin(String uname, String pwd) {
		return uDao.isUserCanLogin(uname, pwd);
	}
	
	@Override
	public Collection<NormalUser> getAll() {
		//TODO
		return null;
	}
	
	@Override
	public void update(NormalUser u) {
		uDao.update(u);
	}

	@Override
	public boolean remove(String id) {
		//TODO
		return false;
	}

	@Override
	public NormalUser getById(String id) {
		//TODO
		return null;
	}

	@Override
	public boolean addUser(NormalUser user) {
		return addUser(user,false);
	}
	
	@Override
	public boolean addUser(NormalUser user,boolean isAdmin) {
		user.setAdmin(isAdmin);
		return uDao.addUser(user);
	}
	
	private Collection<NormalUser> convert(Collection<User> userColl){
		List<NormalUser> userList = new ArrayList<>();
		for (User u : userColl) {
			userList.add((NormalUser)u);
		}
		return userList;
	}
}
